package leetcode;

import java.util.ArrayList;
import java.util.List;

public class lc_139 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("leet");
        list.add("code");
        System.out.println(wordBreak("leetcode",list));
    }
    public static boolean wordBreak(String s, List<String> wordDict) {
        int n = s.length();
        boolean[] dp = new boolean[n + 1];
        dp[0] = true;
        for (int i = 1; i <= n; i++) {
            for (int j = i; j <= n; j++) {
                if(wordDict.contains(s.substring(i - 1, j)) && dp[i - 1]){
                    dp[j] = true;
                }
            }
        }
        return dp[n];
    }
}
